"""
mystr = "lijianqi"

# 通过下表索引取值
x = mystr[2]
y = mystr[-4]
print(f"取出的字母为：{x}，{y}")

# index
values = mystr.index("an")
print(f"在字符串{mystr}中查找an，其起始下标为：{values}")

# replace 字符串替换     语法：字符串.(字符串1,字符串2)  含义：将字符串1替换为字符串2
newstr = mystr.replace("li","李")
print(f"字符串{mystr}替换完的结果是：{newstr}")

# split分割
my_str = "lijianqi liaogong software 22"
my_str_list = my_str.split(" ")
print(f"字符串{my_str}通过split分割后的结果是：{my_str_list}，类型为：{type(my_str_list)}")

# strip方法
my_str1 = "   lijianqi liaogong software 22 "
new_my_str1 = my_str1.strip()   # 未传入参数
print(f"字符串{my_str1}通过strip方法后得结果是：{new_my_str1}")

my_str2 = "56lijianqi liaogong software 65"
new_my_str2 = my_str2.strip("56")   # 传入参数
print(f"字符串{my_str2}通过strip传入参数方法后得结果是：{new_my_str2}")

# 统计字符在字符串中出现的次数
my_str3 = "56lijianqi liaogong software 65"
result = my_str3.count("a")
print(f"字符a在字符串{my_str3}中出现的次数为：{result}")

# 统计字符串的长度
my_str4 = "56lijianqi liaogong software 65"
l = len(my_str4)
print(f"字符串{my_str4}的长度为：{l}")


# 字符串的遍历
my_str5 = "lijianqi"
index = 0
while index <len(my_str5):
    print(f"字符串{my_str5}通过while循环遍历的结果：{my_str5[index]}")
    index += 1

for element in my_str5:
    print(f"字符串{my_str5}通过for循环遍历的结果：{element}")
"""

# 综合练习
str_test = "lijianqi liaogong software"
num = str_test.count("li")
print(f"字符串{str_test}中li的出现次数为：{num}")
new_str_test = str_test.replace(" ","|")
print(f"字符串{str_test}被替换空格后的结果为：{new_str_test}")
value =new_str_test.split("|")
print(f"字符串{new_str_test}，按照|分隔后，得到：{value}")